<template>
  <div class="cont">
    <div class="login">
      <p>注&nbsp;&nbsp;&nbsp;册</p>
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="uname">
          <el-input
            style="width: 350px"
            type="text"
            v-model="ruleForm.uname"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input
            style="width: 350px"
            type="password"
            v-model="ruleForm.pass"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPass">
          <el-input
            style="width: 350px"
            type="password"
            v-model="ruleForm.checkPass"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input
            style="width: 350px"
            type="number"
            v-model="ruleForm.phone"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" class="btn1 btn-danger" @click="register"
        >点击注册</el-button
      >
      <!-- <button type="button" class="btn btn-danger" @click="register">
        注&nbsp;&nbsp;&nbsp;册
      </button>-->
      <div class="text">
        已经有账号了？<router-link to="/login">点击登录</router-link>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    var checkPhone = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入手机号"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("phone");
        }
        callback();
      }
    };
    var checkUname = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入用户名"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("uname");
        }
        callback();
      }
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        pass: "",
        checkPass: "",
        uname: "",
        phone: "",
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }],
        uname: [{ validator: checkUname, trigger: "blur" }],
        phone: [{ validator: checkPhone, trigger: "blur" }],
      },
    };
  },
};
</script>
<style >
.cont {
  margin-bottom: 175px;
  width: 100%;
  height: 793px;
  box-sizing: border-box;
  /* overflow-x: hidden; */
  /* margin: 0px auto; */
  background-image: url("/image/Kkrk4tshRO-rZptVH6XpNA.jpg");
  position: relative;
}
.login {
  width: 500px;
  height: 600px;
  background-color: white;
  background-color: rgba(255, 255, 255, 0.4);
  float: left;
  position: absolute;
  top: 110px;
  left: 900px;
}
p {
  font-size: 36px;
  color: black;

  margin: 20px auto;
  text-align: center;
}
.btn1 {
  display: flex;
  justify-content: center;
  margin-left: 100px;
  width: 390px;
  height: 40px;
  line-height: 20px;
  border: none;
  border-radius: 5px;
  background-color: skyblue;
  color: white;
  font-size: 20px;
}
.btn:hover {
  background-color: #da3481 !important;
}
.text {
  /* background-color: aquamarine; */
  margin: 5px 0px 0px 100px;
  font-size: 14px;
}
</style>